home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / sbin / pppoeconf < prev    next >
Encoding:
Text File  |  2006-11-21  |  17.3 KB  |  469 lines

  1. #!/bin/sh
  2. # (c) Eduard Bloch <blade@debian.org>
  3. # LICENSE: GPL
  4. # Purpose: initial PPPoE configuration on Debian
  5. # Depends: bash, pppd, pppoe, whiptail
  6.  
  7. export TEXTDOMAINDIR="/usr/share/locale"
  8. export TEXTDOMAIN=pppoeconf
  9. export OPTSFILE="/etc/ppp/peers/dsl-provider"
  10. export REALINTFILE="/etc/network/interfaces"
  11.  
  12. # IMPORTANT: Do not use gdialog unless it has been fixed!
  13. DIALOG=whiptail
  14.  
  15. # Set up (X)dialog - added by Fabian Franz <knx-ppp@fabian-franz.de>
  16. XDIALOG_HIGH_DIALOG_COMPAT=1
  17. export XDIALOG_HIGH_DIALOG_COMPAT
  18. if [ -n "$DISPLAY" ] && [ -x /usr/bin/Xdialog ] ; then
  19.   DIALOG="Xdialog"
  20.   X11="-X"
  21. fi
  22.  
  23. # SUID wrapper for KNOPPIX added by Klaus Knopper <knoppix@knopper.net>
  24. # mod. by EB
  25. PATH="/bin:/sbin:/usr/bin:/usr/sbin"
  26. export PATH
  27.  
  28. . /usr/bin/gettext.sh
  29.  
  30. # for non-root, try to reexec with sudo, warn otherwise
  31. if [ "`id -u`" != "0" ]; then
  32.    # sudo only 
  33.   if which sudo >/dev/null && ( sudo -l -S </dev/null >/dev/null 2>&1 ) ; then
  34.     exec sudo "$0" "$@"  || exit 1
  35.   elif which su-to-root >/dev/null; then
  36.     exec su-to-root $X11 -c "$0" "$@"  || exit 1
  37.   else
  38.     gettext "Please become root before running pppoeconf!"
  39.     echo
  40.     gettext "Press return to continue..."
  41.     echo
  42.     read
  43.     exit 1
  44.   fi
  45. fi
  46.  
  47. # EOF SUID wrapper
  48.  
  49. modprobe -q pppoe
  50. # recent ppp packages have a PPPoE discovery helper program
  51. if test -x /usr/sbin/pppoe-discovery && test -e /proc/net/pppoe ; then
  52.   kernel_pppoe=1
  53.   DISCOVERY_PROGRAM=pppoe-discovery
  54. else
  55.   DISCOVERY_PROGRAM=pppoe
  56. fi
  57. export DISCOVERY_PROGRAM
  58.  
  59. # create a default peers file if there is none
  60. if ! test -r $OPTSFILE ; then
  61.    fresh_optsfile=1
  62.    cat <<EOM > $OPTSFILE
  63. # Minimalistic default options file for DSL/PPPoE connections
  64.  
  65. noipdefault
  66. defaultroute
  67. replacedefaultroute
  68. hide-password
  69. #lcp-echo-interval 30
  70. #lcp-echo-failure 4
  71. noauth
  72. persist
  73. #mtu 1492
  74. #persist
  75. #maxfail 0
  76. #holdoff 20
  77. EOM
  78. fi
  79. chmod 0640 $OPTSFILE
  80. chown root:dip $OPTSFILE
  81.  
  82.  
  83. if test "$*" ; then 
  84.    list="$*"
  85.    force_manual=1
  86. else
  87.    list=$( LANG=C /sbin/ifconfig -a | grep "Ethernet" | grep -v irlan | cut -f1 -d" " )
  88. fi
  89.  
  90. if test "$list" ; then
  91.    test "$DIALOG" = "whiptail" && escmsg=$(gettext 'Or press ESC to abort here.')
  92.   number=`echo $list | wc -w| tr -d " "`
  93.   text=$(eval_ngettext \
  94.   'I found $number ethernet device:
  95. $list
  96.  
  97. Are all your ethernet interfaces listed above?
  98. (If No, modconf will be started so you can load the card drivers manually).
  99.  
  100. $escmsg' \
  101.   'I found $number ethernet devices:
  102. $list
  103.  
  104. Are all your ethernet interfaces listed above?
  105. (If No, modconf will be started so you can load the card drivers manually).
  106.  
  107. $escmsg' \
  108.   "$number" )
  109.   title=$(gettext 'ALL DEVICES FOUND?')
  110.   $DIALOG --title "$title" --clear --yesno "$text" 15 60
  111.   case $? in
  112.     1)
  113.     # configure and restart
  114.       modconf
  115.       $0
  116.       exit $?
  117.       ;;
  118.     255)
  119.       rm -rf "$TMP"
  120.       exit 1
  121.       ;;
  122.    esac
  123.  
  124.    INTFILE="`mktemp -t interfaces.pppoeconf.XXXXXX`" || exit 1
  125.    export INTFILE
  126.    cp $REALINTFILE $INTFILE
  127.  
  128.    if ! grep -q "^[^#]*iface[[:space:]]dsl-provider" $INTFILE ; then
  129.       printf '\niface dsl-provider inet ppp\nprovider dsl-provider\n' >> $INTFILE
  130.    fi
  131.  
  132.    umask 177
  133.    # make a secure directory
  134.    TMP="`mktemp -d -p /etc/ppp`"
  135.    export TMP
  136.  
  137.    gettext '
  138. Most providers send the needed login information per mail. Some providers describe it in odd ways, assuming the user to input the data in their "user-friendly" setup programs. But in fact, these applications generate usuall PPP user names and passwords from the entered data. You can find the real names too and input the correct data in the dialog box.
  139.  
  140. For example, this are methods used some german providers:
  141.  
  142. Sample username (alias "login" or "login name"): 11111111111
  143.  
  144. T-Online T-DSL:
  145.   additional data:
  146.     sample T-Onlinenummer: 222222222222
  147.     sample Mitbenutzer: 0001
  148.  
  149.   complete username: 111111111111222222222222#0001@t-online.de
  150.  
  151. Telekom Business Online (DSL):
  152.  
  153.   complete username: t-online-com/111111111111@t-online-com.de
  154.  
  155. 1und1 uses another scheme (using above example):
  156.  
  157.   complete username: 1und1/11111111111
  158.  
  159. Cyberfun:
  160.  
  161.   complete username: sdt/11111111111
  162.  
  163. Komtel:
  164.   additional data:
  165.     downstream speed class: 768
  166.  
  167.   complete username: 11111111111@FoniNet-768
  168.  
  169. Net Cologne:
  170.  
  171.   complete username: 11111111111@netcologne.de
  172.  
  173. Q-DSL:
  174.  
  175.   complete username: 11111111111@q-dsl.de
  176.  
  177. Versatel:
  178.  
  179.   complete username: 11111111111@VersaNet-1024k
  180.  
  181. Webnetix:
  182.  
  183.   complete username: sdt/11111111111
  184. ' > $TMP/namehelp.txt
  185.  
  186.    sectempfile="`mktemp -p $TMP`"
  187.    export sectempfile
  188.    trap "rm -rf '$TMP'" 0 HUP INT TRAP TERM
  189.  
  190.    # now, execute an AC lookup on each interface
  191.    for mmm in '' ' -U ' ; do
  192.       for iface in $list; do
  193.          # use the first candidate only, this is done anyways, below
  194.          if test -z "`grep -l AC $TMP/*.pppoe 2>/dev/null| cut -f1 -d"." | head -n1`" ; then
  195.             title=$(gettext 'SCANNING DEVICE')
  196.             text=$(eval_gettext 'Looking for PPPoE Access Concentrator on $iface...')
  197.             if test -n "$mmm" ; then
  198.                mmode=$(gettext '(multi-modem mode)')
  199.             fi
  200.  
  201.             touch $TMP/pppoe.scan
  202.             ifconfig $iface up
  203.             ($DISCOVERY_PROGRAM $mmm -A -I $iface > $TMP/$iface.pppoe ; rm $TMP/pppoe.scan) &
  204.  
  205.             ( time=0 ; while test -f $TMP/pppoe.scan ; do time=`expr $time + 6`; echo $time; sleep 1; done ) | $DIALOG --title "$title" --gauge "$text $mmode" 10 60 0
  206.  
  207. true
  208.          fi
  209.       done
  210.    done
  211.    cd "$TMP"
  212.    if test "$force_manual" ; then
  213.       iface=$1
  214.    else
  215.       iface=`grep -l AC *.pppoe| cut -f1 -d"." | head -n1`
  216.    fi
  217.    ifacenocomma=$(echo $iface | sed -e 's/,/\\,/g')
  218.  
  219.    if test -z "$iface" ; then
  220.       title=$(gettext 'NOT CONNECTED')
  221.       text=$(eval_ngettext \
  222.       'Sorry, I scanned $number interface, but the Access Concentrator of your provider did not respond. Please check your network and modem cables. Another reason for the scan failure may also be another running pppoe process which controls the modem.' \
  223.       'Sorry, I scanned $number interfaces, but the Access Concentrator of your provider did not respond. Please check your network and modem cables. Another reason for the scan failure may also be another running pppoe process which controls the modem.' \
  224.       $number)
  225.  
  226.       $DIALOG --title "$title" --clear --msgbox "$text" 15 60
  227.       rm -rf "$TMP"
  228.       exit 1;
  229.    fi
  230. #   title=$(gettext 'DSL CONNECTION FOUND')
  231. #   text=$(eval_gettext 'I found an Access Concentrator on $iface. Should I setup PPPOE for this connection?')
  232. #   $DIALOG --title "$title" --clear --yesno "$text" 15 60
  233. #  # STATUS: interface is $iface, we can continue
  234.   
  235.   if ! test "$fresh_optsfile" ; then 
  236.      title=$(gettext 'OKAY TO MODIFY')
  237.      text=$(eval_gettext 'If you continue with this program, the configuration file $OPTSFILE will be modified. Please make sure that you have a backup copy before saying Yes.
  238.  
  239. Continue with configuration?')
  240.      $DIALOG --title "$title" --clear --yesno "$text" 22 70
  241.      if test "$?" != "0" ; then
  242.         rm -rf "$TMP"
  243.         exit 0
  244.      fi
  245.   fi
  246.  
  247.   if ! grep -q "^[^#[:space:]]*auto[[:space:]][^#]*$iface" $INTFILE ; then
  248.       echo >> $INTFILE
  249.       echo "auto $iface" >> $INTFILE
  250.   fi
  251.  
  252.   if ! grep -q "^[^#[:space:]]*iface[[:space:]]\+$iface" $INTFILE ; then
  253.       echo >> $INTFILE
  254.       echo "iface $iface inet manual" >> $INTFILE
  255.   fi
  256.  
  257. #   if test "$?" = "0"; then
  258.       if [ "$kernel_pppoe" ]; then
  259.          # interface activation code - this sucks here, pppd plugin should do it as needed
  260.          #sed -i -e "s,pre-up /sbin/ifconfig[[:space:]]\+[^[:space:]]\+[[:space:]]\+up.#.line.maintained.by.pppoeconf,pre-up /sbin/ifconfig $ifacenocomma up # line maintained by pppoeconf," $INTFILE
  261.     # FIXME: Make sure that it gets added to correct iface stanza! (Because it's not always added above)
  262.     PATTERN_PREUP_IFACE="pre-up /sbin/ifconfig[[:space:]]\+[^[:space:]]\+[[:space:]]\+up.#.line.maintained.by.pppoeconf"
  263.     REPLACE_PREUP_IFACE="pre-up /sbin/ifconfig $ifacenocomma up # line maintained by pppoeconf"
  264.     if grep -q "$PATTERN_PREUP_IFACE" $INTFILE; then 
  265.         sed -i -e "s,$PATTERN_PREUP_IFACE,$REPLACE_PREUP_IFACE," $INTFILE
  266.     else
  267.         sed -i -e "s,[^#]*\(iface dsl-provider.*\),\1\n$REPLACE_PREUP_IFACE," $INTFILE
  268.     fi
  269.  
  270.          # change peers config file, sanity check first
  271. #       grep -q "^plugin.*rp-pppoe.so" $OPTSFILE || echo "plugin rp-pppoe.so $iface" >> $OPTSFILE
  272.        if [ "${iface##eth*}" = "" ]; then
  273.            # Name is eth*
  274.            grep -q "^plugin.*rp-pppoe.so" $OPTSFILE || echo "plugin rp-pppoe.so $iface" >> $OPTSFILE
  275.        else
  276.            grep -q "^plugin.*rp-pppoe.so" $OPTSFILE || echo "plugin rp-pppoe.so" >> $OPTSFILE
  277.            grep -q "^nic-$iface" $OPTSFILE || echo "nic-$iface" >> $OPTSFILE
  278.        fi
  279.  
  280.        # disable the pppoe tunnel command
  281.        if grep -q '^pty' $OPTSFILE ; then
  282.           sed -i -e 's/^pty/#pty/' $OPTSFILE
  283.        fi
  284.  
  285.        # set the interface
  286.        sed -i -e "s,^plugin.\+rp-pppoe.so[[:space:]]\+[^[:space:]]*,plugin rp-pppoe.so $ifacenocomma," $OPTSFILE
  287.        sed -i -e "s,^nic-[[:alnum:]]*,nic-$ifacenocomma," $OPTSFILE
  288.     else
  289.        # sanity check first, fix the config file
  290.  
  291.        # install the default line
  292.        grep -q '^.*pty.*pppoe.*-I' $OPTSFILE || echo 'pty "pppoe -I eth0 -T 80"' >> $OPTSFILE
  293.        # install alternative lines
  294.        grep -q '^.*pty.*pppoe.*-m.*1452' $OPTSFILE || echo '#pty "pppoe -I eth0 -T 80 -m 1452"' >> $OPTSFILE
  295.        grep -q '^.*pty.*pppoe.*-m.*1412' $OPTSFILE || echo '#pty "pppoe -I eth0 -T 80 -m 1412"' >> $OPTSFILE
  296.        # at least one must work
  297.        grep -q '^pty' $OPTSFILE || echo 'pty "pppoe -I eth0 -T 80"' >> $OPTSFILE
  298.  
  299.        # set the interface
  300.        sed -i -e "s,-I[[:space:]]*[[:alnum:]]*,-I $ifacenocomma," $OPTSFILE
  301.     fi
  302.     # fix final newline
  303.     test -e /etc/ppp/pap-secrets && ( [ $(tail -1 /etc/ppp/pap-secrets | wc -l) -eq 0 ] || echo >> /etc/ppp/pap-secrets )
  304.     test -e /etc/ppp/chap-secrets && ( [ $(tail -1 /etc/ppp/chap-secrets | wc -l) -eq 0 ] || echo >> /etc/ppp/chap-secrets )
  305. #  else
  306. #    rm -rf "$TMP"
  307. #    exit 1
  308. #  fi
  309.  
  310.   # ask about sane options
  311.   #$DIALOG --title $"POPULAR OPTIONS" --clear --yesno $"Most people using popular dialup providers prefer the options 'noauth' and 'defaultroute' in their configuration and remove the 'nodetach' option. Further, for busy providers the lcp-echo-interval could be increased. Should I check your configuration file and change these settings where neccessary?" 22 70
  312.   title=$(gettext 'POPULAR OPTIONS')
  313.   text=$(gettext "Most people using popular dialup providers prefer the options 'noauth' and 'defaultroute' in their configuration and remove the 'nodetach' option. Should I check your configuration file and change these settings where neccessary?")
  314.   $DIALOG --title "$title" --clear --yesno "$text" 22 70
  315.   if test "$?" = "0" ; then
  316.     grep -q '^noauth' $OPTSFILE || echo 'noauth' >> $OPTSFILE
  317.     grep -q '^defaultroute' $OPTSFILE  || echo 'defaultroute' >> $OPTSFILE
  318.     sed -i -e "/^nodetach.*/d" $OPTSFILE
  319. #    sed -i -e "s/^lcp-echo-interval 20$/lcp-echo-interval 60/" $OPTSFILE
  320.   fi
  321.   
  322.   user=`grep ^user $OPTSFILE|cut -f2 -d" " | tr -d '"'`
  323.   test -z "$user" && user="username"
  324.   while test "$goahead" != "yes" ; do
  325.     title=$(gettext 'ENTER USERNAME')
  326.     text=$(gettext 'Please enter the username which you usually need for the PPP login to your provider in the input box below. If you wish to see the help screen, delete the username and press OK.')
  327.     $DIALOG --nocancel --title "$title" --clear --inputbox "$text" 15 60 $user 2> "$sectempfile"
  328.     user=`cat "$sectempfile"`
  329.     case $? in
  330.     0)
  331.     if test -z "$user" ; then
  332.       $DIALOG --scrolltext --textbox "$TMP/namehelp.txt" 17 75
  333.     else
  334.       sed -i -e '/^user .*/d' $OPTSFILE
  335.       echo  "user \"$user\"" >> $OPTSFILE
  336.       goahead="yes"
  337.       export goahead
  338.     fi
  339.       ;;
  340.     *)
  341.       exit 1
  342.       rm -rf "$TMP"
  343.       ;;
  344.     esac
  345.   done
  346.  
  347.   title=$(gettext 'ENTER PASSWORD')
  348.   text=$(gettext 'Please enter the password which you usually need for the PPP login to your provider in the input box below.
  349.  
  350. NOTE: you can see the password in plain text while typing.')
  351.   $DIALOG --nocancel --title "$title" --clear --inputbox "$text" 15 60 2> "$sectempfile"
  352.   pass=`cat "$sectempfile"`
  353.   usernoslash=$(echo $user | sed -e 's,/,\\/,')
  354.   case $? in
  355.   0)
  356.     sed -i -e "/^\"*$usernoslash\"* .*/ d" /etc/ppp/pap-secrets
  357.     echo "\"$user\" * \"$pass\"" >> /etc/ppp/pap-secrets
  358.     sed -i -e "/^\"*$usernoslash\"* .*/ d" /etc/ppp/chap-secrets
  359.     echo "\"$user\" * \"$pass\"" >> /etc/ppp/chap-secrets
  360.     ;;
  361.   *)
  362.     rm -rf "$TMP"
  363.     exit 1
  364.     ;;
  365.   esac
  366.  
  367.   # ask about DNS
  368.   title=$(gettext 'USE PEER DNS')
  369.   text=$(gettext 'You need at least one DNS IP address to resolve the normal host names. Normally your provider sends you addresses of useable servers when the connection is established. Would you like to add these addresses automatically to the list of nameservers in your local /etc/resolv.conf file? (recommended)')
  370.   $DIALOG --title "$title" --clear --yesno "$text" 15 60
  371.   case $? in
  372.      0)
  373.      grep -q "^usepeerdns" $OPTSFILE || echo "usepeerdns" >> $OPTSFILE
  374.      ;;
  375.   esac
  376.   
  377.   # ask about MSS limitation
  378.   title=$(gettext 'LIMITED MSS PROBLEM')
  379.   text=$(gettext "Many providers have routers that do not support TCP packets with a MSS higher than 1460. Usually, outgoing packets have this MSS when they go through one real Ethernet link with the default MTU size (1500). Unfortunately, if you are forwarding packets from other hosts (i.e. doing masquerading) the MSS may be increased depending on the packet size and the route to the client hosts, so your client machines won't be able to connect to some sites. There is a solution: the maximum MSS can be limited by pppoe. You can find more details about this issue in the pppoe documentation.
  380.  
  381. Should pppoe clamp MSS at 1452 bytes?
  382.  
  383. If unsure, say yes.
  384.  
  385. (If you still get problems described above, try setting to 1412 in the dsl-provider file.)")
  386.   $DIALOG --title "$title" --clear --yesno "$text" 22 70
  387.   case $? in
  388.      0)
  389.      if [ "$kernel_pppoe" ]; then
  390.         printf '#!/bin/sh\n# Enable MSS clamping (autogenerated by pppoeconf)\n\niptables -t mangle -o "$PPP_IFACE" --insert FORWARD 1 -p tcp --tcp-flags SYN,RST SYN -m tcpmss --mss 1400:1536 -j TCPMSS --clamp-mss-to-pmtu\n' > /etc/ppp/ip-up.d/0clampmss
  391.         printf '#!/bin/sh\n# Disable MSS clamping (autogenerated by pppoeconf)\n\niptables -t mangle -L -n -v --line-numbers | grep "TCPMSS.*$PPP_IFACE.*clamp" | cut -f1 -d " " | xargs -n1 -r iptables -t mangle -D FORWARD\n' > /etc/ppp/ip-down.d/0clampmss
  392.         chmod 755 /etc/ppp/ip-up.d/0clampmss /etc/ppp/ip-down.d/0clampmss
  393.      else
  394.         # disable the old line
  395.         sed -i -e 's/^pty/#&/' $OPTSFILE
  396.         # enable the one with our mss size
  397.         sed -i -e 's/^#\(pty.*-m 1452.*\)/\1/' $OPTSFILE
  398.         #rm -f "$sectempfile"
  399.      fi
  400.      ;;
  401.   esac
  402.  
  403.   if test -z "`mount | grep KNOPPIX`" ; then
  404.      title=$(gettext 'DONE')
  405.      text=$(gettext 'Your PPPD is configured now. Would you like to start the connection at boot time?')
  406.      $DIALOG --title "$title" --clear --yesno "$text" 15 60
  407.      if test "$?" = "0"; then
  408.         grep -q "^auto.*dsl-provider" $INTFILE || sed -i -e 's/^iface.*dsl-provider/auto dsl-provider\n&/' $INTFILE
  409.      else
  410.         sed -i -e '/^auto.*dsl-provider/d' $INTFILE
  411.      fi
  412.   fi
  413.  
  414.   cd /
  415.   
  416.   # end of story
  417.   rm -rf "$TMP"
  418.   chmod --reference=$REALINTFILE $INTFILE
  419.   # check that final file is valid or original one was already invalid. otherwise ask what to do
  420.   ifup -nai $INTFILE 2>/dev/null
  421.   if test "$?" = "1" &&  (ifup -na 2>/dev/null; test "$?" = "0"); then
  422.     title=$(gettext 'ERROR')
  423.     text=$(eval_gettext 'The interfaces file generated by pppoeconf appears to be invalid. This is probably because pppoeconf is unable to handle your original interfaces file. Should pppoeconf nevertheless change your interfaces file with the one that appears to be invalid?
  424. If you agree, you will probably break your network connectivity after rebooting, and cause some local problems if lo is down. Your original interfaces file will be moved to $REALINTFILE~ so you can restore it.
  425. If not, you will have to make sure that $iface is configured before starting your DSL connection and start the connection manually.
  426.  
  427. Note that this situation is not expected and you should consider submitting a bug report against pppoeconf including your original interfaces file and the one generated by pppoeconf.')
  428.     $DIALOG --title "$title" --clear --defaultno --yesno "$text" 20 75
  429.     if test "$?" = "0"; then
  430.       mv -b $INTFILE $REALINTFILE
  431.     fi
  432.   else
  433.     mv $INTFILE $REALINTFILE
  434.   fi
  435.  
  436.   title=$(gettext 'ESTABLISH A CONNECTION')
  437.   text=$(gettext 'Now, you can make a DSL connection with "pon dsl-provider" and terminate it with "poff". Would you like to start the connection now?')
  438.   $DIALOG --title "$title" --clear --yesno "$text" 15 60
  439.   case $? in
  440.   0)
  441.     cd /
  442.     pon dsl-provider
  443.     title=$(gettext 'CONNECTION INITIATED')
  444.     text=$(gettext 'The DSL connection has been triggered. You can use the "plog" command to see the status or "ifconfig ppp0" for general interface info.')
  445.     $DIALOG --title "$title" --clear --msgbox "$text" 10 60
  446.     ;;
  447.   *)
  448.     exit 0
  449.     ;;
  450.   esac
  451.  
  452. else
  453.   title=$(gettext 'NO INTERFACE FOUND')
  454.   text=$(gettext 'Sorry, no working ethernet card could be found. If you do have an interface card which was not autodetected so far, you probably wish to load the driver manually using the modconf utility. Run modconf now?')
  455.   $DIALOG --title "$title" --clear --yesno "$text" 20 70
  456.   case $? in
  457.   0)
  458.     rm -rf "$TMP"
  459.     modconf
  460.     exec $0
  461.     exit $?
  462.     ;;
  463.   *)
  464.     rm -rf "$TMP"
  465.     exit 1
  466.     ;;
  467.   esac
  468. fi
  469.